﻿function showNewUserModal() {
    layer.open({
        type: 1,
        title: '新建用户',
        shadeClose: true,
        shade: 0.8,
        area: ['880px', '90%'],
        scrollbar: false,
        content: $('#newUserModal') //捕获的元素
    });
}

function newUserInfo() {
    var datas = $('#newUserInfo').serializeArray();
    var $alert = $('#alert');

    if ($alert.is(':visible'))
        $('#alert').css('visibility', 'hidden');

    $.post('newuserinfo', datas).success(function (res) {
        if (!res.Success) {
            $alert.text(res.ErrorMessage);
            $alert.css('visibility', 'visible');
        } else {
            window.location.reload();
        }
    }).error(function () {
        alert('服务员异常');
    });
}

$('#newUserInfo').validate({
    submitHandler: function (form) {
        newUserInfo();
    },
    messages: {
        email: '邮箱格式不正确',
        password: '密码不得少于6位',
        repeatPassword: {
            equalTo: '两次密码不一致'
        },
        fullName: '用户姓名2-4个中文'
    },
    rules: {
        repeatPassword: { equalTo: '#password' }
    }
})


function edit(uid) {
    layer.open({
        type: 2,
        title: '编辑用户',
        shadeClose: true,
        shade: 0.8,
        area: ['880px', '60%'],
        scrollbar: false,
        content: '/member/edit?uid=' + uid //捕获的元素
    });
}

function refreash() {
    window.location.reload();
}

function totalCheck(evt) {
    var isChecked = $(evt).is(':checked');
    $('#table-form').find('input[name="uids"]').attr('checked', isChecked);
}

function editUserStatus(status) {
    var datas = $('#table-form').serializeArray();
    datas.push({
        name: 'status',
        value: status
    });

    if (datas.length == 0) return;

    $.post('/member/edituserstatus', datas).success(function () {
        window.location.reload();
    }).error(function () {
        alert('服务器异常');
    });
}